//
//  MBStoreSrv.m
//  MBObjectServer
//
//  Created by Juvid on 14-4-23.
//  Copyright (c) 2014年 MBpayer. All rights reserved.
//

#import "MBStoreSrv.h"

@implementation MBStoreSrv
-(id)init{
    self=[super init];
    if (!self) {
        return nil;
    }
    baseserver = [[MBBaseServer alloc]init];
    return self;
}
-(void)GetTree:(NSString *)storeId Success:(ReceiveSuccess)processSuccess Failure:(ReceiveFailure)processFailure{
    
    NSMutableDictionary* postDic=[[NSMutableDictionary alloc]init];
    //    [postDic setObject:@"A00064S101" forKey:@"storeId"];
    [baseserver setRequestMBStyle:nil andSetPathString:@"getTree.shtml" andSetHeadString:nil andActionName:@"getTree" andSetMainDictionary:postDic block:^(NSDictionary *responseData) {
        
        processSuccess([responseData objectForKey:@"rData"]);
        //        [selfCtr ScanBarCodeResult:responseData Success:processSuccess];
    }failblock:^(NSError *error) {
        processFailure(error);
    }];
    
}
#pragma mark hennychen
-(void)SearchTagType:(int)tagType
         CurrentPage:(int)currentPage
            PageSize:(int)pageSize
           SearchKey:(NSString *)searchKey
             Success:(ReceiveSuccess)processSuccess
             Failure:(ReceiveFailure)processFailure{
    NSMutableDictionary* postDic=[[NSMutableDictionary alloc]init];
    [postDic setObject:@"A00064S101" forKey:@"storeId"];
    //    if (tagType==1) {
    
    [postDic setObject:[NSNumber numberWithInt:tagType] forKey:@"tagType"];
    //    }
    
    if (searchKey.length<8) {
        [postDic setObject:[NSString stringWithFormat:@"%@*",searchKey] forKey:@"colorSn"];
    }
    else{
        [postDic setObject:searchKey forKey:@"colorSn"];
    }

    [postDic setObject:[NSNumber numberWithInt:currentPage] forKey:@"current_page"];
    [postDic setObject:[NSNumber numberWithInt:pageSize] forKey:@"page_size"];

    
    
    [baseserver setRequestMBStyle:nil andSetPathString:@"search.shtml" andSetHeadString:nil andActionName:@"search" andSetMainDictionary:postDic block:^(NSDictionary *responseData) {
        //        NSLog(@"%@",responseData);
        processSuccess(responseData );
        //        [selfCtr ScanBarCodeResult:responseData Success:processSuccess];
    }failblock:^(NSError *error) {
        processFailure(error);
    }];
    
}


-(void)SearchTagType:(int)tagType
         CurrentPage:(int)currentPage
            PageSize:(int)pageSize
               CatID:(int)catID
           SearchKey:(NSString *)searchKey
             Success:(ReceiveSuccess)processSuccess
             Failure:(ReceiveFailure)processFailure{
    NSMutableDictionary* postDic=[[NSMutableDictionary alloc]init];
    [postDic setObject:@"A00064S101" forKey:@"storeId"];
    [postDic setObject:[NSNumber numberWithInt:tagType] forKey:@"tagType"];
    [postDic setObject:[NSNumber numberWithInt:currentPage] forKey:@"current_page"];
    [postDic setObject:[NSNumber numberWithInt:pageSize] forKey:@"page_size"];
    if (tagType==1) {
        [postDic setObject:@"MB|MM" forKey:@"brandCode"];
           //判断是否纯数字
        if ([CustomClass isPureInt:searchKey]) {
            if (searchKey.length<8) {
                [postDic setObject:[NSString stringWithFormat:@"%@*",searchKey] forKey:@"colorSn"];
            }else{
                [postDic setObject:searchKey forKey:@"colorSn"];
            }
        }else {
            [postDic setObject:searchKey forKey:@"goodsName"];
        }
        if (catID>0) {
            [postDic setObject:[NSNumber numberWithInt:catID] forKey:@"catId"];
        }
    }
    
    [baseserver setRequestMBStyle:nil andSetPathString:@"search.shtml" andSetHeadString:nil andActionName:@"search" andSetMainDictionary:postDic block:^(NSDictionary *responseData) {
        //        NSLog(@"%@",responseData);
        processSuccess(responseData );
        //        [selfCtr ScanBarCodeResult:responseData Success:processSuccess];
    }failblock:^(NSError *error) {
        processFailure(error);
    }];
    
}
-(void)getGoodsInfo:(int)tagType
            ColorSn:(NSString *)colorSn
            Success:(ReceiveSuccess)processSuccess
            Failure:(ReceiveFailure)processFailure{
    NSMutableDictionary* postDic=[[NSMutableDictionary alloc]init];
    [postDic setObject:@"A00064S101" forKey:@"storeId"];
    [postDic setObject:[NSNumber numberWithInt:tagType] forKey:@"tagType"];
    [postDic setObject:colorSn forKey:@"itemId"];
    [baseserver setRequestMBStyle:nil andSetPathString:@"getGoodsInfo.shtml" andSetHeadString:nil andActionName:@"getGoodsInfo" andSetMainDictionary:postDic block:^(NSDictionary *responseData) {
        NSLog(@"%@",responseData);
        processSuccess([responseData objectForKey:@"rData"]);
        //        [selfCtr ScanBarCodeResult:responseData Success:processSuccess];
    }failblock:^(NSError *error) {
        processFailure(error);
    }];
    
}
@end
